#include <stdio.h>
#include "Clib.h"
#include "http_packet_parsing.h"
#include "websocket_packet_parsing.h"

int main(void)
{
	uint8_t buf[500] = {"123fdsFsFDasd4324HTTP/1.1 200 OK\r\n\
Server: openresty\r\n\
Date: Wed, 09 Nov 2016 08:29:47 GMT\r\n\
Content-Type: application/json\r\n\
Content-Length: 56\r\n\
Connection: keep-alive\r\n\r\n\
{\"error\":0,\"reason\":\"ok\",\"IP\":\"54.223.34.73\",\"port\":443}56468"};

	uint8_t str[10] = {0x81,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9E};
	uint8_t s[] = "{\"error\":404,\"reason\":\"Not Found\",\"deviceid\":\"10000294df\",\"apikey\":\"4328c6f4-577e-493c-8cfa-9c7fdd1fef2c\",\"config\":{\"regInterval\":15},\"actionName\":\"register\"}";
	uint8_t src[200] = {0};
	uint8_t tmp_buf[500] = {0};
	uint8_t test[10] = {0};
	uint32_t i;

#if 0
	if (check_http_packet_rece_finish(buf,500))
	{
		get_http_packet_content(buf,HTTP_HEAD,tmp_buf);
		printf("%s\n",tmp_buf);
		clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_SERVER,tmp_buf);
		printf("%s\n",tmp_buf);
		clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_DATE,tmp_buf);
		printf("%s\n",tmp_buf);
		clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_CONTENT_TYPE,tmp_buf);
		printf("%s\n",tmp_buf);
	    clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_CONTENT_LENGTH,tmp_buf);
        printf("%s\n",tmp_buf);
        clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_CONNECTION,tmp_buf);
		printf("%s\n",tmp_buf);
		clear_string_buf(tmp_buf,200);

		get_http_packet_content(buf,HTTP_DATA,tmp_buf);
		printf("%s\n",tmp_buf);
		clear_string_buf(tmp_buf,200);
	}
#endif

	for(i=0;i<158;i++)
	{
		str[i+10] = s[i];
	}
	if(check_websocket_packet_rece_finish(str,168)  == GET_OK)
	{
		i = get_websocket_packet_head(str, WEBSOCKET_FIN_RSV);
		printf("%x ", i);
		i = get_websocket_packet_head(str, WEBSOCKET_OPCODE);
		printf("%x ", i);
		i = get_websocket_packet_head(str, WEBSOCKET_MASK);
		printf("%x ", i);
		i = get_websocket_packet_head(str, WEBSOCKET_PAYLOAD_LEN);
		printf("%x ", i);
		i = get_websocket_packet_head(str, WEBSOCKET_MASK_KEY);
		printf("%x ", i);
		i = get_websocket_packet_head(str, WEBSOCKET_EXTENDED_PAYLEN);
		printf("%x\n", i);
		get_websocket_packet_data(str, src);
		printf("%s", src);
	}

	flodou_to_string(3012.1232,test,4,4);
	printf("%s\n", test);

	return 0;
}
